package com.ca.ridersclubapplication.util;

import java.math.BigDecimal;
import java.math.RoundingMode;

public class ScoreUtils {

    public static int parseScore(String score) {

        if (score == null || score.trim().isEmpty()) {
            return 0;
        }

        try {
            return (int) Float.parseFloat(score);
        }
        catch (Exception e) {
            return 0;
        }
    }

    public static String scoreToString(float score) {

        if (score == 0) {
            return "0.0";
        }

        score = BigDecimal.valueOf(score)
                .setScale(1, RoundingMode.HALF_DOWN)
                .floatValue();

        int v = (int) (score * 10);

        int z = v / 10;
        int x = v % 10;

        return z + "." + x;
    }
}
